//
//  MainViewController.swift
//  SinaWeiBo
//
//  Created by dengchen on 15/11/8.
//  Copyright (c) 2015年 name. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func clickComposedButton() {
        
        let nav = UINavigationController(rootViewController: ComposeViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let maintabbar = MainTabBar()
        
       maintabbar.composeBtn.addTarget(self, action: "clickComposedButton", forControlEvents: UIControlEvents.TouchUpInside)
        
        setValue(maintabbar, forKey: "tabBar")
        
        addChildViewControllers()
        
    }

    private func addChildViewControllers() {

    addChildViewController(HomeTableViewController(), imageName:"tabbar_home", title:"主页")
    addChildViewController(MessageTableViewController(), imageName:"tabbar_message_center", title:"消息")
    addChildViewController(DiscoverTableViewController(), imageName:"tabbar_discover", title:"发现")
    addChildViewController(ProfileTableViewController(), imageName:"tabbar_profile", title:"我")

    }

   private func addChildViewController(childController: UIViewController,imageName:String,title:String) {

        let nav:baseNavigationController  = baseNavigationController(rootViewController: childController)

        addChildViewController(nav)

        childController.title = title
        childController.tabBarItem.image  = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")



    }


}
